﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace RSHTreelReset
{
    sealed class EncryptionUtil
    {
        public const string DES_KEY = "ReSharper DES key";
        private const string PREFIX = "E.";

        public static string Encrypt(string settingValue)
        {
            using (StringEncryption stringEncryption = new StringEncryption(StringEncryption.StringEncryptionMethod.DES))
                return stringEncryption.Encrypt(settingValue, "ReSharper DES key");
        }

        public static string Decrypt(string encryptedValue)
        {
            using (StringEncryption stringEncryption = new StringEncryption(StringEncryption.StringEncryptionMethod.DES))
                return stringEncryption.Decrypt(encryptedValue, "ReSharper DES key");
        }

        public static string GetEncryptedString(string value)
        {
            if (string.IsNullOrEmpty(value) || !value.StartsWith("E."))
                return (string)null;
            else
                return EncryptionUtil.Decrypt(value.Substring("E.".Length));
        }
    }
}
